package com.bw.my.mvvm.model.entity.usergreendao;

import org.greenrobot.greendao.query.WhereCondition;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class UserDaoImpl<T> implements DaoInterface<T> {

    private Class cs;

    public UserDaoImpl() {
        ParameterizedType type = (ParameterizedType) getClass().getGenericSuperclass();
        cs = (Class) type.getActualTypeArguments()[0];
    }

    @Override
    public boolean insert(T t) {
        long l = DaoSessionUtils.getInstance().getSession().insertOrReplace(t);

        return l>0;
    }

    @Override
    public T select(WhereCondition condition) {
        T t = (T) DaoSessionUtils.getInstance().getSession()
                .queryBuilder(cs).where(condition)
                .unique();
        return t;
    }
}
